      <div class="templatemo-content-wrapper">
        <div class="templatemo-content">
          <ul class="nav nav-tabs mytabs">
        	 <li class="active"><a href="<?php echo site_url('product/index/id/'.$product['id'])?>">编辑商品</a></li>
		  	 <li><a href="<?=site_url()?>/product/index">商品列表</a></li>
		  	 <li><a href="<?=site_url()?>/product/add">添加商品</a></li>
		  </ul>
          <div class="row">
            <div class="col-md-12">
              <div class="table-responsive">
                 <form role="form" id="templatemo-preferences-form" onsubmit="return false;">
                 	<input type="hidden" id="id" value="<?php echo $product['id']; ?>" />
                 	<div class="row">
                 	   <div class="col-md-6 margin-bottom-15">
	              		<label for="firstName" class="control-label">商品图片</label>
	              		<input class="file-" type="file"  id="img" name="Filedata"/>
                		<input id="pic" name="pic" type="hidden" class="input" value="<?php echo $product['image']; ?>">
                		<img id="img_product" src="http://7xj0kd.com2.z0.glb.qiniucdn.com/<?php echo $product['image']; ?>" width="100px;" style="margin-top:20px;" />
                	  </div>
                  </div>
                  <div class="row">
                  <div class="col-md-6 margin-bottom-15">
                    <label for="firstName" class="control-label">商品名称</label>
                    <input type="text" class="form-control" id="name" value="<?php echo $product['name']; ?>">
                  </div>
                  <div class="col-md-6 margin-bottom-15">
                    <label for="lastName" class="control-label">分类</label>
                    <select class="form-control margin-bottom-15" id="category">
                  		 <?php foreach ($categories as $item):?>
                   		 <option value="<?php echo $item['id'];?>" <?php if($item['id'] == $product['categoryid']) echo "selected"; ?>><?php echo $item['name'];?></option>
                     	<?php endforeach;?>
                  	</select>
                  </div>
                  <div class="col-md-6 margin-bottom-15">
                    <label for="firstName" class="control-label">价 格</label>
                    <input type="text" class="form-control" id="price" value="<?php echo $product['price']; ?>">
                  </div>

	                <div class="col-md-6 margin-bottom-15">
                    <label for="lastName" class="control-label">单 位</label>
                    <input type="text" class="form-control" id="unit" value="<?php echo $product['unit']; ?>">
                  </div>

                  <div class="col-md-6 margin-bottom-15">
                    <label for="lastName" class="control-label">商品描述</label>
                    <input type="text" class="form-control" id="description" value="<?php echo $product['description']; ?>">
                  </div>


                  <div class="col-md-6 margin-bottom-15">
                    <label for="lastName" class="control-label">限 量</label>
                    <input type="text" class="form-control" id="daylim" value="<?php echo $product['daylim']; ?>">
                  </div>


                  </div>
	              <div class="row templatemo-form-buttons">
	                <div class="col-md-12">
	                  <button type="submit" class="btn btn-primary" id="submit_btn">修改</button>
	                </div>
                  </div>
                </form>
              </div>
            </div>
          </div>
        </div>
      </div>
<script>
	$(document).ready(function() {
		$('#img').ajaxfileupload({
				'action' : '<?php echo site_url('up/up_pic')?>',
				'params' : {
					'path' : 'product/pic'
				},
				onStart: function() {

				},
				'onComplete' : function(response) {
					if ( typeof response === 'string') {
						var files = response.replace(/\\/g, '/');
						$("#img_product").attr("src",'http://7xj0kd.com2.z0.glb.qiniucdn.com/'+files);
						$("#pic").val(files);
						alert("上传成功！");
					} else {
						alert("上传的文件格式不正确");
					}
				}
			});

		$("#submit_btn").click(function() {
			var id = $("#id").val();
			var image = $("#pic").val();
			var name = $("#name").val();
			var categoryid = $("#category").val();
			var price = $("#price").val();
			var unit = $("#unit").val();
			var description = $("#description").val();
			var week = $("#week").val();
			var select = $("#select").val();
      var daylim = $('#daylim').val();

			if(name == ''){
				alert('名称不能为空')
				return;
			}


			$.ajax({
				url : '<?php echo site_url('product/save')?>',
				type : "post",
				async : false,
				data : {
					'id' : id,
					'image' : image,
					'name' : name,
					'categoryid' : categoryid,
					'price' : price,
					'unit' : unit,
					'description' : description,
					'week' : week,
					'select' : select,
          'daylim': daylim
				},
				dataType : "json",
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						//window.location.reload();
					}else{
						alert(data.msg);
					}

				}
			});
		});
	});
</script>
